/*	kd:
	
	This is a new version of an old struct that maintains an array of faders,
	meaning you can tell a value to move from a start to an end value over a
	certain time frame (with a constant speed you give it at the start).
	
	Example usage is in the shop. The selection offsets and all the buttons
	fading in, out, moving, etc. are all inside one of these.
	
	*/

struct Gc_NormalFades {
	private Array <double>				current;
	private Array <double>				step;
	private uint						count;
	
	void Reset () {
		for(let i = 0; i < count; i++) {
			current	[i] = 0;
			step	[i] = 0;
		}
	}
	
	void ClearAndResize (uint size) {
		current.clear();
		step.clear();
		
		current.reserve(size);
		step.reserve(size);
		count = size;
		
		Reset();
	}
	
	uint Register () {
		current.push(0);
		step.push(0);
		count = current.size();
		return count - 1;
	}
	
	bool IsIndexValid (int fader_index) const {
		if(fader_index < 0 || count <= fader_index) {
			return false;
		}
		
		return true;
	}
	
	void ToEnd (int fader_index, int tics = 1) {
		step [fader_index] = 1.0 / max(1, tics);
	}
	
	void ToStart (int fader_index, int tics = 1) {
		step [fader_index] = -1.0 / max(1, tics);
	}
	
	void ForceToStart (int fader_index) {
		step	[fader_index] = 0;
		current	[fader_index] = 0;
	}
	
	void NextState () {
		for(let i = 0; i < count; i++) {
			current [i] = clamp(current [i] + step [i], 0, 1);
		}
	}
	
	double At (int fader_index, double t = 1) const {
		return clamp(current [fader_index] + t * step [fader_index], 0, 1);
	}
}